package com.db4o.odbgen.plugins.java.maingenerator.typedxmlschema;

import java.util.ArrayList;
import java.util.List;

import com.db4o.internal.odbgen.StringUtils;
import com.db4o.odbgen.plugins.xmlschema.Element;

public class TSInterface implements XmlElement, TypeDeclaration{

	private List<String> _imports;
	private List<TSModifier> _modifiers;
	private Element _element;
	private String _package;
	private String _simpleName;
	private List<TSGetterSetter> _getterSetters;

	/**
	 * Constructs a new interface given it's components.
	 * @param element
	 * @param pkg
	 * @param simpleName
	 * @param getterSetters The list of getter/setters of this interface.
	 */
	public TSInterface(
			Element element, 
			String pkg, 
			List<TSModifier> modifiers,
			String simpleName, 
			List<TSGetterSetter> getterSetters
			){
		this._element = element;
		this._package = pkg;
		this._modifiers = modifiers;
		this._simpleName = simpleName;
		this._getterSetters = getterSetters;
		
		this._imports = new ArrayList<String>();
	}
	
	/**
	 * See {@link XmlElement} for details.
	 */
	@Override
	public Element getElement() {
		return this._element;
	}

	/**
	 * See {@link TypeDeclaration} for more details.
	 */
	@Override
	public String getPackage() {
		return this._package;
	}

	/**
	 * See {@link TypeDeclaration} for more details.
	 */
	@Override
	public String getQualifiedName() {
		return this._package+(this._package.length()==0?"":".")+this._simpleName;
	}

	/**
	 * See {@link TypeDeclaration} for more details.
	 */
	@Override
	public String getSimpleName() {
		return this._simpleName;
	}

	public List<TSGetterSetter> getGetterSetters(){
		return this._getterSetters;
	}

	/**
	 * Returns the list of imports needed for this interface.
	 */
	public List<String> getImports(){
		return this._imports;
	}
	
	/**
	 * Returns the modifiers of this interface.
	 */
	public List<TSModifier> getModifiers(){
		return this._modifiers;
	}
	
	/**
	 * Returns a string representing this object.
	 * This is used for debug purposes.
	 * @param tabs Number of tabs to indent.
	 */
	String toString(int tabs) {
		StringBuilder res = new StringBuilder();
		
		res.append(String.format("%sinterface", StringUtils.tabs(tabs)));
		res.append(StringUtils.newLine());

		res.append(String.format("%sname=%s",
				StringUtils.tabs(tabs+1),
				this.getQualifiedName()
				));
		res.append(StringUtils.newLine());
		
		for(TSGetterSetter gs : this.getGetterSetters()){
			res.append(gs.toString(tabs+1));
			res.append(StringUtils.newLine());
		}
		
		return res.toString();
	}

	
}
